// Copyright (c) 2014 Jonathan Magnan (http://jonathanmagnan.com/).
// All rights reserved (http://zzzproject.com/icon-library/).
// Licensed under MIT License (MIT) (https://ziconlibrary.codeplex.com/license).

// All icons are licensed under a Creative Commons Attribution 3.0 License.
// http://creativecommons.org/licenses/by/3.0/us/
// Copyright 2009-2013 FatCow Web Hosting. All rights reserved.
// http://www.fatcow.com/free-icons


using System;
using System.ComponentModel;
using System.Reflection;


public static partial class IconExtensions
{
    /// <summary>
    ///     An Icon extension method that gets URL to use with the IconResourceHandler for the 16x16 icon.
    /// </summary>
    /// <param name="this">The @this to act on.</param>
    /// <returns>The URL to use with the IconResourceHanler for the Icon.</returns>
    public static string GetUrl(this Z.IconLibrary.FarmFresh16.Icon @this)
    {
        Type enumType = typeof (Z.IconLibrary.FarmFresh16.Icon);
        FieldInfo fi = enumType.GetField(@this.ToString());
        var attributes = (DescriptionAttribute[]) fi.GetCustomAttributes(typeof (DescriptionAttribute), false);

        if (attributes.Length > 0)
        {
            return "Z.IconLibrary.FarmFresh16.axd?f=Icon." + attributes[0].Description;
        }
        return null;
    }
}
